﻿using System;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Xml;

namespace WcfExtensions.ServiceModel.TestClient.Scenarios.Xml
{
    [DataContract(Namespace = "http://localhost/wcftest/newsmessage")]
    internal class XmlMessage
    {
        [DataMember(IsRequired = true)]
        public DateTime TimeStamp;

        [DataMember(IsRequired = true)]
        public XmlElement Document;
    }

    [ServiceContract]
    internal interface IXmlService
    {
        [OperationContract]
        string SendMessage(XmlMessage message);
    }

    internal sealed class XmlService : IXmlService
    {
        public string SendMessage(XmlMessage message)
        {
            Stopwatch watch = Stopwatch.StartNew();

            string document = message.Document.OuterXml;

            watch.Stop();

            return String.Format("Deserialized xml in {0} ms. Total character count: {1}", watch.ElapsedMilliseconds,
                                 document.Length);
        }
    }
}
